package com.cq.hd.member.controller;

import com.alibaba.fastjson.JSONObject;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbMemberFeeConfigApi;

import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.*;
import com.cq.hd.member.service.TbMemberFeeConfigService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 会员套餐配置表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-12-05
 */
@RestController
public class TbMemberFeeConfigController implements TbMemberFeeConfigApi {

    @Autowired
    private TbMemberFeeConfigService memberFeeConfigService;

    @ApiOperation(value = "保存会员套餐配置")
    @ApiImplicitParam(name = "memberFeeConfigSaveDto", value = "保存参数", required = true, paramType = "body", dataType = "MemberFeeConfigSaveDto")
    @Override
    public Result<Long> saveMemberFeeConfig(@RequestBody MemberFeeConfigSaveDto memberFeeConfigSaveDto) {
        return ResultGenerator.success(memberFeeConfigService.saveMemberFeeConfig(memberFeeConfigSaveDto));
    }

    @ApiOperation(value = "更新会员套餐配置")
    @ApiImplicitParam(name = "memberFeeConfigUpdateDto", value = "更新参数", required = true, paramType = "body", dataType = "MemberFeeConfigUpdateDto")
    @Override
    public Result<Boolean> updateMemberFeeConfig(@RequestBody MemberFeeConfigUpdateDto memberFeeConfigUpdateDto) {
        return ResultGenerator.success(memberFeeConfigService.updateMemberFeeConfig(memberFeeConfigUpdateDto));
    }

    @ApiOperation(value = "管理后台会员套餐配置列表")
    @ApiResponse(response = MemberFeeConfigPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<MemberFeeConfigPageVo>> pageMemberFeeConfig(MemberFeeConfigPageDto memberFeeConfigPageDto) {
        return ResultGenerator.success(memberFeeConfigService.pageMemberFeeConfig(memberFeeConfigPageDto));
    }

    @ApiOperation(value = "商家端会员套餐配置列表")
    @ApiResponse(response = AppMemberFeeConfigPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AppMemberFeeConfigPageVo>> pageAppMemberFeeConfig(AppMemberFeeConfigPageDto appMemberFeeConfigPageDto) {
        return ResultGenerator.success(memberFeeConfigService.pageAppMemberFeeConfig(appMemberFeeConfigPageDto));
    }

    @ApiOperation(value = "创建订单，返回充值订单号")
    @ApiImplicitParam(name = "appMemberFeeConfigCreateDto", value = "实体", required = true, paramType = "body", dataType = "AppMemberFeeConfigCreateDto")
    @Override
    public Result<String> createAppMemberFeeConfigOrder(@RequestBody AppMemberFeeConfigCreateDto appMemberFeeConfigCreateDto) {
        return ResultGenerator.success(memberFeeConfigService.createAppMemberFeeConfigOrder(appMemberFeeConfigCreateDto));
    }

    @ApiOperation(value = "立即支付，唤起第三方支付")
    @ApiImplicitParam(name = "appMemberFeeConfigPayDto", value = "实体", paramType = "body", dataType = "AppMemberFeeConfigPayDto")
    @ApiResponse(response = AppMemberFeeConfigPayVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppMemberFeeConfigPayVo> payAppMemberFeeConfigOrder(@RequestBody AppMemberFeeConfigPayDto appMemberFeeConfigPayDto) {
        return ResultGenerator.success(memberFeeConfigService.payAppMemberFeeConfigOrder(appMemberFeeConfigPayDto));
    }

    @ApiOperation(value = "聚合正扫下单回调")
    @Override
    public Result<Boolean> jsPayCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(memberFeeConfigService.jsPayCallback(dataObj));
    }

    @ApiOperation(value = "查单（只要唤醒了第三方支付，关闭第三方支付页面之后，不管是成功还是失败，都要调用）")
    @Override
    public Result<Boolean> queryOrderPay(@RequestBody AppMemberFeePayQueryDto appMemberFeePayQueryDto) {
        return ResultGenerator.success(memberFeeConfigService.queryOrderPay(appMemberFeePayQueryDto));
    }

    @ApiOperation(value = "赠送会员")
    @Override
    public Result<Boolean> giveMemberFee(@RequestBody MemberFeeGiveDto memberFeeGiveDto) {
        return ResultGenerator.success(memberFeeConfigService.giveMemberFee(memberFeeGiveDto));
    }

    @ApiOperation(value = "修改权益")
    @Override
    public Result<Boolean> changeRights(MemberFeeChangeDto memberFeeChangeDto) {
        return ResultGenerator.success(memberFeeConfigService.changeRights(memberFeeChangeDto));
    }

    @ApiOperation(value = "获取会员配置详情")
    @Override
    public Result<MemberFeeConfigPageVo> detailById(Long id) {
        return ResultGenerator.success(memberFeeConfigService.detailById(id));
    }

    @ApiOperation(value = "网银支付开通会员")
    @Override
    public Result<BankPayRechargeVo> bankPayAdminMemberFeeConfigOrder(@RequestBody AdminBusinessMemberFeePayDto adminBusinessMemberFeePayDto) {
        return ResultGenerator.success(memberFeeConfigService.bankPayAdminMemberFeeConfigOrder(adminBusinessMemberFeePayDto));
    }

    @ApiOperation(value = "网银支付查单")
    @Override
    public Result<BankPayQueryVo> queryBankPayOrder(@RequestBody BankPayQueryDto bankPayQueryDto) {
        return ResultGenerator.success(memberFeeConfigService.queryBankPayOrder(bankPayQueryDto));
    }

    @ApiOperation(value = "网银开通会员回调")
    @Override
    public Result<Boolean> bankPayCallback(@RequestBody JSONObject dataObj) {
        return ResultGenerator.success(memberFeeConfigService.bankPayCallback(dataObj));
    }
}
